﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Job.Web.Framework;
using Job.Logic.Personal;

namespace Job.Web.userControls.Personal
{
    public partial class PersonClob : BaseCtrl
    {
        int rsubjectId = myR["subjectid"].IntValue;
        int _personId = myR["resumeid"].IntValue;

        PersonalLogic logic = new PersonalLogic();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.messageTd.Visible = false;
            if (!IsPostBack)
            {
                try
                {
                    LoadData();
                }
                catch (Exception ex)
                {
                    ShowMessage("查询失败：" + ex.Message);
                    this.btnSave.Enabled = false;
                    this.tbMemo.Enabled = false;
                }
            }
        }

        private void ShowMessage(string message)
        {
            this.messageTd.InnerHtml = "<font color='#990000'>" + message + "</font>";
            this.messageTd.Height = "30px";
            this.messageTd.VAlign = "middle";
            this.messageTd.Visible = true;
        }

        private bool LoadData()
        {
            string text = "";
            string title = "";
            switch (rsubjectId)
            {
                case (int)Constants.ResumeSubject.OtherDesc:
                    title = "附加信息";
                    text = logic.GetPersonOtherDesc(_personId);
                    break;
                case (int)Constants.ResumeSubject.ForeignResume:
                    title = "外文简历";
                    text = logic.GetPersonForeignResume(_personId);
                    break;
                default:
                    title = "自我简介";
                    text = logic.GetPersonDesc(_personId);
                    break;
            }
            this.titleTd.InnerText = title;
            this.tbMemo.Text = text;
            return true;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string content = tbMemo.Text;
                content = (null == content) ? "" : content;

                switch (rsubjectId)
                {
                    case (int)Constants.ResumeSubject.OtherDesc:
                        logic.SavePersonOtherDesc(_personId, content);
                        break;
                    case (int)Constants.ResumeSubject.ForeignResume:
                        logic.SavePersonForeignResume(_personId, content);
                        break;
                    default:
                        logic.SavePersonDesc(_personId, content);
                        break;
                }
                ShowMessage("保存" + this.titleTd.InnerText + "成功！");
            }
            catch (Exception ex)
            {
                ShowMessage("保存" + this.titleTd.InnerText + "失败：" + ex.Message);
            }
        }
    }
}